package com.hongye.controller;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import com.alipay.api.AlipayApiException;
import com.hongye.app.model.BuyerStatisticsModel;
import com.hongye.app.model.EmployeeManageModel;
import com.hongye.app.model.OrderInfoModel;
import com.hongye.util.AlipayUtils;
import com.hongye.util.JuheUtils;
import com.hongye.util.KDNiaoUtils;
import com.hongye.util.PushUtils;
import com.hongye.util.WeixinUtils;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.DbKit;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.upload.UploadFile;

/**
 * 测试相关
 * @author Administrator
 *
 */
public class TestController extends Controller{
	
	public TestController() {
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * 参数接收——String
	 * this.getParam
	 * @author lifuqiang
	 * 2016-10-31
	 * @param param
	 * @return
	 */
	public String getPa(String param) {
		return this.getPara(param);
	}
	
	/**
	 * 参数接收——int
	 * this.getParaToInt
	 * @author lifuqiang
	 * 2016-11-14
	 * @return
	 */
	@Clear
	public int getParaInt(String param){
		return this.getParaToInt(param);
	}
	
	/**
	 * 参数接收——UploadFile
	 * this.getFile
	 * @author lifuqiang
	 * 2017-2-4
	 * @return
	 */
	public UploadFile getfile(String fileName){
		int maxPostSize = 20 * 1024 * 1024;
		return this.getFile(fileName, "", maxPostSize);
	}
	
	/**
	 * 测试环信 接口
	 * @author liushaomin 
	 * 2016年10月12日
	 */
	@Clear
	public void testhuanxin(){
//		this.renderJson(HuanXinUtils.addUsers("15933675785", "123456", "liu"));
//		this.renderJson(HuanXinUtils.getToken());
//		this.renderJson(HuanXinUtils.getSingleUser("15031554160"));
//		this.renderJson(HuanXinUtils.resetPassword("15031554160", "789456123"));
//		this.renderJson(HuanXinUtils.resetNickName("15031554160", "刘少敏"));
//		this.renderJson(HuanXinUtils.getUserStatus("15933675785"));
	}
	
	/**
	 * 测试快递鸟 接口
	 * @author lifuqiang
	 * 2016-10-21
	 * @throws Exception 
	 */
	@Clear
	public void testkdniao(){
		this.renderJson(KDNiaoUtils.getOrderJson("BTWL", "70219717438640"));
//		this.renderJson(KDNiaoUtils.numberRecognition("416710755623"));
//		this.renderJson(KDNiaoUtils.getOrderJson("HHTT", "667041672428"));
//		this.renderJson(KDNiaoUtils.orderTracesSubByJson("ZTO", "419530805333"));
//		this.renderJson(KdniaoController.orderTracesSubByJson("YD", "3984678212826"));
	}
	
	/**
	 * 测试支付宝
	 * @author lifuqiang
	 * 2016-11-29
	 * @throws AlipayApiException 
	 */
	@Clear
	public void testAlipay(){
//		this.renderHtml(AlipayUtils.AlipayForService(Utils.getOrderSN(),"15031554160", "刘少敏", 0.1, "测试"));
//		boolean boo = AlipayController.getAlipayUserInfo("201611BB3098dd7b72464b829c6a3e9525d39X33");
//		if(log.isInfoEnabled()){log.info("boolean="+boo);}
//		System.err.println(Utils.urlEncoder(AlipayUtils.RETURN_URL_APP, "UTF-8"));
		AlipayUtils.refund("20170116162042495", "0.10");
	}
	
	@Clear
	public void testJiGuang(){//15731130434
//		this.renderJson(PushUtils.MSG_All("rebogou_all"));
		this.renderJson(PushUtils.MSG_Single("15733265915", "1", "系统测试！"));
//		this.renderJson(PushUtils.MSG_UserType("商家","商家推送"));
	}
	
	/**
	 * 测试微信
	 * @author lifuqiang
	 * 2017-2-15
	 * @throws Exception 
	 */
	@Clear
	public void testweixin() throws Exception{
//		System.err.println(WeixinUtils.getRandomString(32));
		System.err.println(WeixinUtils.refund(getPa("out_trade_no"),Double.parseDouble(getPa("total_fee")), Double.parseDouble(getPa("refund_fee"))));
	}
	
	/**
	 * 测试聚合
	 * @author lifuqiang
	 * 2017-2-17
	 */
	@Clear
	public void testJuhe(){
//		System.err.println(JuheUtils.bankcardsilk("6217000010077230202"));
//		System.err.println(JuheUtils.verifybankcard4("李富强", "130827199401284416", "6217000010077230202", "15933675785"));
		System.err.println(JuheUtils.verifybankcard4(getPa("realname"), getPa("idcard"), getPa("bankcard"), getPa("mobile")));
	}
	
	@Clear
	public void test(){
		OrderInfoModel order = OrderInfoModel.getOrderBySN("20170328110428247");
		BuyerStatisticsModel.Update_Add_Usable(order);
	}
	
	/**
	 * 测试事务回滚
	 * @author lifuqiang
	 * 2017-4-21
	 * @throws SQLException 
	 */
	@Clear
	@Before(Tx.class)  // 业务层使用事务拦截器
	public void testTransaction() throws SQLException{
		String id = this.getPa("id");
		String status = this.getPa("status");
		Map<String, Object> rs = new HashMap<String, Object>();
		EmployeeManageModel.update(id, status);
		boolean boo = false;
		if(boo){
			DbKit.getConfig().getConnection().rollback();
			rs.put("state", "fal");
		}else{
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
}
